package com.douhuang.cloud.resp;

import lombok.Data;

@Data
public class R<T> {

    private String code;/** 结果状态 ,具体状态码参见枚举类ReturnCodeEnum.java*/
    private String message;
    private T data;
    private long timestamp ;


    public R (){
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> R<T> success(T data) {
        R<T> resultData = new R<>();
        resultData.setCode(ReturnCodeEnum.RC200.getCode());
        resultData.setMessage(ReturnCodeEnum.RC200.getMessage());
        resultData.setData(data);
        return resultData;
    }

    public static <T> R<T> fail(String code, String message) {
        R<T> resultData = new R<>();
        resultData.setCode(code);
        resultData.setMessage(message);

        return resultData;
    }
}
